<template>
	<view>
		<view class="header">
			<view class="bg">
				<view class="box">
					<view class="box-hd" v-if="UserDetails">
						<view class="avator">
							<img :src="UserDetails.uImage">
						</view>
						<view class="phone-number">{{UserDetails.uName}}</view>
					</view>
					<view class="box-hd" @click="Login" v-else>
						<view class="avator">
							<img src="../../static/user/face.jpg">
						</view>
						<view class="phone-number">请登录</view>
					</view>
					<view class="box-bd">
						<view class="item" v-for="(item,index) in FirstList" :key="index" @click="ListClick(item)">
							<view class="icon"><img :src="item.icon"></view>
							<view class="text">{{item.label}}</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="list-content">
			<view class="list">
				<view class="li" v-for="(item,index) in SecondList" :key="index" :class="index==0?'':'noborder'"
					@click="ListClick(item)">
					<view class="icon">
						<image :src="item.icon"></image>
					</view>
					<view class="text">{{item.label}}</view>
					<image class="to" src="../../static/user/to.png"></image>
				</view>
			</view>
			<view class="list">
				<view class="li" v-for="(item,index) in ThreeList" :key="index" @click="ListClick(item)">
					<view class="icon">
						<image :src="item.icon"></image>
					</view>
					<view class="text">{{item.label}}</view>
					<image class="to" src="../../static/user/to.png"></image>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	import http from "../../static/http.js"
	export default {
		data() {
			return {
				FirstList: [{
					icon: "../../static/user/opinion.png",
					label: "意见反馈",
					url: "/pages/my/idea"
				}, {
					icon: "../../static/user/favorite.png",
					label: "我的优惠券",
					url: "/pages/my/myyhq"
				}],
				SecondList: [{
					icon: "../../static/user/card.png",
					label: "个人信息",
					url: "mydetails"
				}],
				ThreeList: [{
						icon: "../../static/user/about.png",
						label: "关于我们",
						url: "our"
					},
					{
						icon: "../../static/user/sj.png",
						label: "退出",
						url: "out"
					}
				],
				UserDetails: ""
			};
		},
		onLoad() {},
		created() {
			this.getUserInfo()
		},
		methods: {
			ListClick(item) {
				if (item.url == 'out') {
					uni.showModal({
						title: '提示',
						content: '确认退出吗？',
						success: function(res) {
							if (res.confirm) {
								uni.clearStorageSync()
								uni.reLaunch({
									url:"/pages/login/login"
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
				} else if(item.url == "our") {
					uni.showModal({
						title: '提示',
						content: '努力、奋斗！',
						success: function(res) {
							if (res.confirm) {
							} else if (res.cancel) {
							}
						}
					});
				} else if(item.url == "mydetails"){
					uni.showModal({
						title: '个人信息',
						content: `用户名：${this.UserDetails.uName} \n 邮箱：${this.UserDetails.uEmail} \n 身份：${this.UserDetails.role?"管理员":"普通用户"}`,
						success: function(res) {
							if (res.confirm) {
							} else if (res.cancel) {
							}
						}
					});
				}else{
					uni.navigateTo({
						url: item.url
					})
				}

			},
			// 获取个人信息
			getUserInfo() {
				http.httpRequest("/admin/userInfo", "", "POST").then(res => {
					console.log(res);
					this.UserDetails = res.data
				})
			},
			Login() {
				uni.reLaunch({
					url:"/pages/login/login"
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f1f1f1;
		font-size: 30upx;
	}

	.header {
		background: #fff;
		height: 290upx;
		padding-bottom: 110upx;

		.bg {
			width: 100%;
			height: 200upx;
			padding-top: 100upx;
			background-color: #4191ea;
		}
	}

	.box {
		width: 650upx;
		height: 280upx;
		border-radius: 20upx;
		margin: 0 auto;
		background: #fff;
		box-shadow: 0 5upx 20upx 0upx rgba(0, 0, 150, .2);

		.box-hd {
			display: flex;
			flex-wrap: wrap;
			flex-direction: row;
			justify-content: center;

			.avator {
				width: 160upx;
				height: 160upx;
				background: #fff;
				border: 5upx solid #fff;
				border-radius: 50%;
				margin-top: -80upx;
				overflow: hidden;

				img {
					width: 100%;
					height: 100%;
				}
			}

			.phone-number {
				width: 100%;
				text-align: center;
			}
		}

		.box-bd {
			display: flex;
			flex-wrap: nowrap;
			flex-direction: row;
			justify-content: center;

			.item {
				width: 33%;
				display: flex;
				flex-wrap: wrap;
				flex-direction: row;
				justify-content: center;
				border-right: 1px solid #f1f1f1;
				margin: 15upx 0;

				.btn {
					color: #333;
					border: none;
					border-radius: 0;
					background-color: transparent;

					&::after {
						border: none !important;
					}
				}

				&:last-child {
					border: none;
				}

				.icon {
					width: 60upx;
					height: 60upx;

					img {
						width: 100%;
						height: 100%;
					}
				}

				.text {
					width: 100%;
					text-align: center;
					margin-top: 10upx;
				}
			}
		}
	}

	.list-content {
		background: #fff;
	}

	.list {
		width: 100%;
		border-bottom: 15upx solid #f1f1f1;
		background: #fff;

		&:last-child {
			border: none;
		}

		.li {
			width: 92%;
			height: 100upx;
			padding: 0 4%;
			border-bottom: 1px solid rgb(243, 243, 243);
			display: flex;
			align-items: center;

			&.noborder {
				border-bottom: 0
			}

			.icon {
				flex-shrink: 0;
				width: 50upx;
				height: 50upx;

				image {
					width: 50upx;
					height: 50upx;
				}
			}

			.text {
				padding-left: 20upx;
				width: 100%;
				color: #666;
			}

			.to {
				flex-shrink: 0;
				width: 40upx;
				height: 40upx;
			}
		}
	}
</style>
